"use strict";

/**
 * Created by xuchao on 15/10/16.
 */
angular.module('app.controller', ['cloudatum.util','akoenig.deckgrid'])
  .controller('InitCtrl', function (RestService, $stateParams, $state, $window) {
    RestService.getInfo($stateParams.activityId).$promise.then(function (data) {
      console.log(data);
      var originalId = angular.fromJson(data.activity).originalId;
      console.log(originalId);
      RestService.getWxConfig($window.location.href.split('#')[0], originalId).$promise.then(function (d) {
        console.log(d);
        wx.config({
          debug: false,
          appId: d.appId,
          timestamp: d.timestamp,
          nonceStr: d.nonceStr,
          signature: d.signature,
          jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
        });

        wx.ready(function () {
          if($stateParams.itemId){
            $state.go('detail', {id: $stateParams.itemId, openid: $stateParams.openid, activityId: $stateParams.activityId});
          }else{
            $state.go('home', {openid: $stateParams.openid, activityId: $stateParams.activityId});
          }
        });



      });
    });
  });
